n = int(input())

class node:
    health = 0
    attack = 0
    def __init__(self,health,attack):
        self.health = health
        self.attack = attack


first = [node(30,0)]
second = [node(30,0)]

flag = 1

for i in range(0,n):
    line = input().split()
    if line[0] == "summon":
        position,attack,health = map(int,line[1:])
        if flag:
            first.insert(position,node(health,attack))
        else:
            second.insert(position,node(health,attack))
    elif line[0] == "attack":
        p1,p2 = map(int,line[1:])
        if flag:
            first[p1].health-=second[p2].attack
            second[p2].health-=first[p1].attack
            if first[p1].health <= 0 and p1 != 0:
                first.pop(p1)
            if second[p2].health <= 0 and p2 != 0:
                second.pop(p2)
        else:
            first[p2].health-=second[p1].attack
            second[p1].health-=first[p2].attack
            if first[p2].health <= 0 and p2 != 0:
                first.pop(p2)
            if second[p1].health <= 0 and p1 != 0:
                second.pop(p1)

    else:
        flag = 1 - flag

if first[0].health <= 0:
    print(-1)
elif second[0].health <= 0:
    print(1)
else:
    print(0)

print(first[0].health)

print(len(first) - 1,end=" ")
for item in first[1:]:
    print(item.health,end=" ")
print("")

print(second[0].health)

print(len(second) - 1,end=" ")
for item in second[1:]:
    print(item.health,end=" ")
print("")
